// index.js
var activity_js = require('../../../utils/activity.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rightArrow: "../../../image/mine-menu/right-arrow.png",
    nav: ["我发布的", "组织发布", "我关注的", "我参加的"],
    currentTab: 0,
    activity_list: [],
    info: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
      wx.setStorageSync("activity_create_type", 1);
      console.log('onLoad');
      var that = this;
      //var activity_list = res.data.data;
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function (userInfo) {
        //更新数据
        that.setData({
          userInfo: userInfo
        })
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      var that = this;
      activity_js.organized_all_my_list(function (res){
        console.log(res);
        if (res.op != "fail") {
          var my_all_activity = res.data.data;
          that.setData({
            my_all_activity: my_all_activity,
          });
        }
        that.refresh_activity_list();
      });
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }, 
    
    // 上导航栏选择
    navtap: function (e) {
      var that = this;
      console.log(e);
      var currentTab =e.target.dataset.id;
      this.setData({
        currentTab: currentTab,
      })
      that.refresh_activity_list();
    }, 
    refresh_activity_list: function () {
      var that = this;
      var currentTab = that.data.currentTab;
      var my_all_activity = that.data.my_all_activity;
      switch (currentTab) {
        case 0 :
          that.setData({
            activity_list: my_all_activity.my_create_activity_list,
          });
          break;
        case 1 :
          that.setData({
            activity_list: my_all_activity.my_org_create_activity_list,
          });
          break; 
        case 2:
          that.setData({
            activity_list: my_all_activity.my_subscribe_activity_list,
          });
          break;
        case 3:
          that.setData({
            activity_list: my_all_activity.my_join_activity_list,
          });
          break;
      }
    }
  })